<template>
  <div class="app-container">
    <bread parentPathText="信访管理" currentPathText="信访信息管理"/>
    <el-form :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="日期选择">
        <el-date-picker
          v-model="date"
          value-format="yyyy-MM-dd"
          type="daterange"
          size="mini"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="信访方式">
        <el-select
          v-model="queryParams.method"
          placeholder="请选择方式"
          clearable
          size="small"
          style="width: 260px"
          @change="methodChange"
        >
          <el-option
            v-for="item in methodData"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="筛选类型">
        <el-select
          v-model="queryParams.type"
          placeholder="选择类型"
          clearable
          size="small"
          style="width: 260px"
          @change="typeChange"
        >
          <el-option
            v-for="item in types"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="queryParams.info"
          placeholder="请输入姓名/电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="tableList">
      <el-table-column
        align="center"
        label="信访人"
        prop="userName"
        min-width="20%"
      />
      <el-table-column
        align="center"
        label="信访人数"
        prop="num"
        :show-overflow-tooltip="true"
        min-width="15%"
      />
      <el-table-column
        align="center"
        label="信访方式"
        prop="patternVal"
        :show-overflow-tooltip="true"
        min-width="20%"
      />
      <el-table-column
        align="center"
        label="问题发生地"
        prop="address"
        min-width="20%"
      />
      <el-table-column
        align="center"
        label="联系电话"
        prop="tel"
        min-width="30%"
      />
      <el-table-column
        align="center"
        label="信访事件"
        prop="event"
        min-width="15%"
      />
      <el-table-column
        align="center"
        label="信访内容"
        prop="eventDescription"
        min-width="15%"
      />
      <el-table-column
        align="center"
        label="登记单位"
        prop="registUnit"
        min-width="15%"
      />
      <el-table-column
        align="center"
        label="信访日期"
        prop="visitTime"
        min-width="15%"
      />
      <el-table-column
        align="center"
        label="操作"
        min-width="25%"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-view"
            @click="handleUpdate(scope.row)"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加/编辑弹框 -->
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="30%"
      append-to-body
    >
     <el-form
        ref="ruleForm"
        label-width="100px"
      >
        <el-form-item label="信访人：">
          {{ detail.userName }}
        </el-form-item>
        <el-form-item label="信访人数：">
          {{ detail.num }}
        </el-form-item>
        <el-form-item label="信访方式：">
          {{ detail.patternVal }}
        </el-form-item>
        <el-form-item label="问题发生地：">
          {{ detail.address }}
        </el-form-item>
        <el-form-item label="联系电话：">
          {{ detail.tel }}
        </el-form-item>
        <el-form-item label="信访事件：">
          {{ detail.event }}
        </el-form-item>
        <el-form-item label="信访内容：">
          {{ detail.eventDescription }}
        </el-form-item>
        <el-form-item label="登记单位：">
          {{ detail.registUnit }}
        </el-form-item>
        <el-form-item label="信访日期：">
          {{ detail.visitTime }}
        </el-form-item>
     </el-form>
    </el-dialog>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      class="pagination"
    >
    </el-pagination>
  </div>
</template>
<script>
import initPagin from '../mixins/index.js'
export default {
  mixins:[initPagin],
  data() {
    return {
      date: "",
      queryParams: {
        method: "",
        type: "",
        info: "",
      },
      methodData: [
        {
          label: "全部",
          value: 0,
        },
        {
          label: "申述信",
          value: 1,
        },
        {
          label: "来电申述",
          value: 2,
        },
        {
          label: "当面申述",
          value: 3,
        },
        {
          label: "网上申述",
          value: 4,
        },
      ],
      types: [
        {
          label: "全部",
          value: 0,
        },
        {
          label: "姓名",
          value: 1,
        },
        {
          label: "电话",
          value: 2,
        },
      ],
      loading: false,
      detail:{
        userName:'',
        num:'',
        patternVal:'',
        address:'',
        tel:'',
        event:'',
        eventDescription:'',
        registUnit:'',
        visitTime:''
      },
      // 弹框
      title: "查看详情",
      dialogVisible: false,
      time: new Date().getTime(),
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 搜索按钮操作
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    // 重置按钮操作
    resetQuery() {
       Object.keys(this.queryParams).forEach((key) => {
            this.queryParams[key] = "";
        });
        this.date = '';
    },
    // 获取列表
    getList() {
      this.loading = true;
      let params = {
        time: this.time,
        pageNum:this.pageNum,
        pageSize:this.pageSize,
        startTime: this.date ? this.date[0] : "",
        endTime: this.date ? this.date[1] : "",
        status: this.queryParams.type,
        pattern: this.queryParams.method,
        queryMsg: this.queryParams.info,
      };
      let result = this.$md5.transferValue(params);
      this.axios
        .post(this.stateUrl.petition.list, {
          time: this.time,
          pageNum:this.pageNum,
          pageSize:this.pageSize,
          startTime: this.date ? this.date[0] : "",
          endTime: this.date ? this.date[1] : "",
          status: this.queryParams.type,
          pattern: this.queryParams.method,
          queryMsg: this.queryParams.info,
          sign: this.$md5.val(result)
        })
        .then((res) => {
          this.loading = false;
          this.tableList = res.data.data;
          this.total = res.data.count;
        })
        .catch(() => {});
    },
    // 查看
    handleUpdate(row){
      this.dialogVisible = true;
      let params = {
        time:this.time,
        id:row.id
      }
      let result = this.$md5.transferValue(params);
      this.axios.post(this.stateUrl.petition.detail,{
        time:this.time,
        id:row.id,
        sign: this.$md5.val(result)
      }).then(res=>{
        this.detail.userName = res.data.data.userName;
        this.detail.num = res.data.data.num;
        this.detail.patternVal = res.data.data.patternVal;
        this.detail.address = res.data.data.address;
        this.detail.tel = res.data.data.tel;
        this.detail.event = res.data.data.event;
        this.detail.eventDescription = res.data.data.eventDescription;
        this.detail.registUnit = res.data.data.registUnit;
        this.detail.visitTime = res.data.data.visitTime;
      }).catch(()=>{})
    },
    // 选择信访方式
    methodChange(val) {
      this.queryParams.method = val;
    },
    // 选择类型
    typeChange(val) {
      this.queryParams.type = val;
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
<style lang="less" scoped>
</style>